import * as types from '../actionsType'
import { http } from '@/utiles'

// 获取频道列表
const getChannels = () => {
  return async (dispatch) => {
    const res = await http.get('/channels')
    dispatch({
      type: types.GET_CHANNELS,
      payload: res.data.data.channels,
    })
  }
}
// 获取文章列表
const getArticles = () => {
  return async (dispatch) => {
    const res = await http.get('/mp/articles')
    console.log(res.data.data);
    const {
      page,
      per_page: pageSize,
      results: list,
      total_count: count
    } = res.data.data
    dispatch({
      type: types.GET_ARTICLES,
      payload: {
        page,
        pageSize,
        count,
        list: list.map(item => {
          return {
            ...item,
            cover: item.cover.images[0]
          }
        })
      }
    })
  }
}
export { getChannels, getArticles }
